<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tool-edit" th:object="${factoryTool}">
            <input name="factoryId" th:field="*{factoryId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">父节点id：</label>
                <div class="col-sm-8">
                    <input name="parentId" th:field="*{parentId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="factoryName" th:field="*{factoryName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">进料容量：</label>
                <div class="col-sm-8">
                    <input name="enterCapacity" th:field="*{enterCapacity}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">出料容量：</label>
                <div class="col-sm-8">
                    <input name="outputCapacity" th:field="*{outputCapacity}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">显示顺序：</label>
                <div class="col-sm-8">
                    <input name="sequenceId" th:field="*{sequenceId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">图片：</label>
                <div class="col-sm-10">
                    <input name="factoryImg" th:field="*{factoryImg}" id="pic" class="form-control" type="hidden">
                    <a id="url"><img th:src="*{factoryImg}" style="width: 90px;height: 90px"></a>
                    <input type="file" id="factoryImg">
                    <!--                    <input type="button" id="sc" value="上传">-->

                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">分类状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                        <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "factory/factory";
        $("#form-tool-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-tool-edit').serialize());
            }
        }
        // 上传文件
        $("#factoryImg").change(function () {
            var data = new FormData();
            data.append("file", $("#factoryImg")[0].files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    // alert(JSON.stringify(result))
                    if (result.code == web_status.SUCCESS) {
                        $("#url img").attr("src",result.fileName)
                        $("#pic").val(result.fileName)
                    }
                },
                error: function(error) {
                    alert("图片上传失败。");
                }
            });
        })

    </script>
</body>
</html>